//
//  MainViewController.swift
//  sinaweibo
//
//  Created by mac on 15/11/8.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //实现 撰写 按钮的点击事件
    @objc private func didClickComposeBtn() {
        //打印方法名
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = MainTabBar()
        //tabbar 是只读 不能直接直接操作 如果要修改 需要KVC
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewControllers()
        //打印tabbar的类名  看是否是自定义的MainTarBar
//        print(tabBar.classForCoder)
        
        //给 "+" 添加点击事件
        mainTabBar.composeBtn.addTarget(self, action: "didClickComposeBtn", forControlEvents: .TouchUpInside)
        
    }

    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", image: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController, title : String, image : String) {
        
        self.tabBar.tintColor = UIColor.orangeColor()
        let nav = BaseNavgationController(rootViewController: vc)

        vc.title = title
        vc.tabBarItem.image = UIImage(named: image)
        
        addChildViewController(nav)
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
